﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PerfumeShopManagement.Model;

namespace PerfumeShopManagement.DAL
{
    public class DalRepositoryHistory : DalAbstractBase<RepositoryHistory, int>
    {
        public override RepositoryHistory GetObjectById(int id)
        {
            throw new NotImplementedException();
        }

        public override List<RepositoryHistory> GetAllObjects()
        {
            var result = (from r in _context.RepositoryHistories
                          select r);
            if (result != null)
                return result.ToList<RepositoryHistory>();

            return new List<RepositoryHistory>();
        }

        public override List<RepositoryHistory> GetObjectsByCriteria(RepositoryHistory obj)
        {
            throw new NotImplementedException();
        }

        public override bool Insert(RepositoryHistory obj)
        {
            RepositoryHistory repositoryHistory = obj;

            _context.RepositoryHistories.AddObject(repositoryHistory);
            _context.SaveChanges();

            return true;
        }

        public override bool Update(RepositoryHistory obj)
        {
            RepositoryHistory repositoryHistory = obj;

            RepositoryHistory repositoryHistoryRow = _context.RepositoryHistories.Single(
                r => r.HistoryId == repositoryHistory.HistoryId);
            repositoryHistoryRow.ProductId = repositoryHistory.ProductId;
            repositoryHistoryRow.ActivityKind = repositoryHistory.ActivityKind;
            repositoryHistoryRow.ActiveTime = repositoryHistory.ActiveTime;
            _context.SaveChanges();

            return true;
        }

        public override bool DeleteById(int id)
        {
            throw new NotImplementedException();
        }
    }
}
